<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<div class="panel">

  <div class="panel-heading">
    <ul class="nav nav-tabs">
      <li class="active"><a  href="#s1" id="first1" data-toggle="tab">基本设置</a></li>
      <li class="disabled"><a  href="#s2" id="other1" data-toggle="tab">步骤列表</a></li>
    </ul>
  </div>
  <div class="tab-content">
    <div class="tab-pane fade in active" id="s1">
      <form id="form_processBrief_input" class="form-horizontal">
        <input type="hidden" name="keyId" id="keyId" value="${keyId}"/>
        <input type="hidden"  id="archReaderId" name="archReaderId" value="${creadConfig.id}">
        <input type="hidden"  id="archEditorId" name="archEditorId" value="${ceditConfig.id}">
        <input type="hidden"  id="docReaderId"  name="docReaderId" value="${cdocConfig.id}">
        <div id="title" class="panel-heading  header" >
          <h3 class="panel-title">流程简要表</h3>
        </div>
        <div class="form-group">
          <label class="col-md-2 control-label">流程名称<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="text"  name="processName" id="processName" class="form-control" placeholder="请填写流程名称"
                   value="${processBrief.name}">
          </div>
        </div>
        <div class="form-group">
          <label class="col-md-2 control-label">关联表单<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
              <select class="form-control" name="tableKey" id="tableKey">
                <option value=""></option>
                <c:forEach items="${entityDatas}" varStatus="i" var="list" >
                  <option value="${list.key}" ${list.selected}>${list.value}</option>
                </c:forEach>
              </select>
          </div>

        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">是否共享<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <div class="radio">
              <input type="radio" name="share" id="shareYes" value="是" class="magic-radio" <c:if test="${processBrief.share=='是'}"> checked</c:if> >
              <label for="shareYes">是</label>
              <input type="radio" name="share" id="shareNo" value="否" class="magic-radio" <c:if test="${processBrief.share=='否'}"> checked</c:if> >
              <label for="shareNo">否</label>
            </div>
          </div>
        </div>

        <div class="panel-heading header">
          <h3 class="panel-title" style="display: inline-block">文档归档后配置</h3>
          <a key="archReader_href" href="javascript:void(0);">
                  <span class="txt-color-blueDark pull-right" style="font-size:16px">
                          <i class="fa-fw fa fa-wrench"></i> 读者类型<span></span>
                  </span>
          </a>
          <a key="archEditor_href" href="javascript:void(0);">
                <span class="txt-color-blueDark pull-right" style="font-size:16px">
                        <i class="fa-fw fa fa-wrench"></i> 编辑者类型<span></span>
                </span>
          </a>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label"  style="color:#4FA5D0">读者</label>

        </div>
        <div id="archReaderDiv" >
        </div>
        <div class="form-group">
          <label class="col-md-2 control-label" style="color:#4FA5D0">编辑者</label>
        </div>
        <div id="archEditorDiv">
        </div>
        <div class="panel-heading header">
          <h3 class="panel-title" style="display: inline-block">其他配置</h3>
          <a key="docReader_href" href="javascript:void(0);">
            <span class="txt-color-blueDark pull-right" style="font-size:16px">
                    <i class="fa-fw fa fa-wrench"></i> 文档阅览者<span></span>
            </span>
          </a>
        </div>
        <div id="docReaderDiv">

        </div>
      </form>
      <div class="panel-footer">
        <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
          <i class="fa fa-lg fa-mail-reply"></i> 返回视图
        </a>

        <a class="btn btn-warning" id="btn-submit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交表单 </a>

      </div>
    </div>
    <div class="tab-pane fade in active" id="s2" style="margin: 10px;"></div>
  </div>
</div>





<script>

  $(function(){
      var keyId = $('#keyId').val();
      if(keyId != ""){
          $('#other1').parent('li').removeClass('disabled');
      }
      var table_global_width=0;
      $("a#other1").off("click").on("click",function(e) {
          if(keyId != "") {
              if (table_global_width == 0) {
                  table_global_width = $("#s1").is(":visible") ? $("#s1").width() : $("#s2").width();
              }
              $('div').data("table_global_width", table_global_width);
              loadURL("menu/stepBrief?parentId=" + $("#keyId").val(), $('div#s2'));
          }else{
              return false;
          }
      });
      $('a#first1').off("click").on("click",function(e) {
          $('div#s2').empty();
      });
      loadURL("<%=path%>/main/commoncfg/read?keyId="+$("#archReaderId").val(),$("#archReaderDiv"));
      loadURL("<%=path%>/main/commoncfg/read?keyId="+$("#archEditorId").val(),$("#archEditorDiv"));
      loadURL("<%=path%>/main/commoncfg/read?keyId="+$("#docReaderId").val(),$("#docReaderDiv"));
      fn_processBrief_input_validate();

      $("a[key$='_href']").unbind("click").bind("click",function(){
          var key = $(this).attr("key");
          var type = key.split("_")[0];
          // console.debug(type);
          var tableKey = $('#tableKey').val();
          var keyId = $("input#"+type+"Id").val();
          __open_dialog_form('配置权限', '<%=path%>/main/commoncfg/input?keyId='+keyId+'&selectType='+type+'&tableKey='+tableKey, function (dialogRef) {
              var callback = function (data) {
                  if (data) {
                      dialogRef.close();
                      // 刷新主表
                      $("#"+data.selectType+"Div").empty();
                      $("#"+data.selectType+"Id").val(data.keyId);
                      loadURL("<%=path%>/main/commoncfg/read?keyId="+data.keyId,$("#"+data.selectType+"Div"));
                  } else {
                      dialogRef.enableButtons();
                  }
              };
              if (fn_commoncfg_input_save(callback) === false) {
                  dialogRef.enableButtons();
              }
          });

      });

  });



  // 表单数据校验
  function fn_processBrief_input_validate() {
    __init_validate('form_processBrief_input', {
        rules : {
            processName : {
                required : true
            },
            tableKey:{
                required : true
            }
        },
        messages : {
            processName : {
                required : '请填写流程名称'
            },
            tableKey:{
                required : '请选择关联表单'
            }
        }
    });
  }



  //返回视图
  $("#apply-re-common").click(returnToHashUrl);

  //提交
  $("#btn-submit-common").click(
      function(e) {
          if (!$("#form_processBrief_input").valid()) {
              return false;
          }
          __confirm_dialog("提示：","确定提交吗？",
              function () {
                  __form_save("form_processBrief_input", "<%=path%>/main/processBrief/save", function(){
                      $("#apply-re-common").trigger('click');
                  });

              }
          )
      }
  );
</script>